//Copyright 2008 Kristian Gundry And Rune Juhl-Petersen
//This file is part of Plain.

//Plain is free software: you can redistribute it and/or modify
//it under the terms of the GNU Lesser General Public License as published by
//the Free Software Foundation, either version 3 of the License, or
//any later version.

//Plain is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//GNU Lesser General Public License for more details.

//You should have received a copy of the GNU Lesser General Public License
//along with Plain.  If not, see <http://www.gnu.org/licenses/>.
using System;

namespace Plain.Utilities{
	/// <summary>
	/// Description of IntegerExtensions.
	/// </summary>
	public static class IntegerExtensions{
		public static TimeSpan Seconds(this int i){
			return new TimeSpan(0,0,i);
		}
		public static TimeSpan Minutes(this int i){
			return new TimeSpan(0,i,0);
		}
		public static TimeSpan Hours(this int i){
			return new TimeSpan(i,0,0);
		}
		public static TimeSpan Days(this int i){
			return new TimeSpan(i * 24,0,0);
		}
		public static TimeSpan Weeks(this int i){
			return new TimeSpan(7 * 24 * i,0,0);
		}
        /// <summary>
        /// lets you repeat something a certain number of times
        /// </summary>
        /// <param name="i"></param>
        /// <returns>an array</returns>
        public static int[] Times(this int i) {
            int[] ii = new int[i];
            while (--i > -1) {
                ii[i] = i;
            }
            return ii;
        }

        public static int[] To(this int from, int to) {
            if (from < to) {
                int[] ii = new int[to - from + 1];
                for (int x = from, i = 0; x <= to; x++, i++) {
                    ii[i] = x;
                }
                return ii;
            } else {
                int[] ii = new int[from - to + 1];
                for (int x = from, i = 0; x >= to; x--, i++) {
                    ii[i] = x;
                }
                return ii;
            }
        }
		
		
		public static DateTime Ago(this TimeSpan span){
			return DateTime.Now.Add(-span);
		}
		public static DateTime Ahead(this TimeSpan span){
			return DateTime.Now.Add(span);
		}
		public static DateTime After(this TimeSpan span, DateTime time){
			return time.Add(span);
		}
		public static DateTime Before(this TimeSpan span, DateTime time){
			return time.Add(-span);
		}
	}
}
